<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增短信模板')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-msgTemplate-add">
        <input name="id" th:value="${id}" type="hidden">
        <input name="paramNum" th:value="${paramNum}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">参数：</label>
            <div class="col-sm-8">
                <input name="params" id="params" class="form-control" type="text" placeholder="多个参数中间用英文逗号隔开" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机号：</label>
            <div class="col-sm-8">
                <input name="phoneNum" id="phoneNum" class="form-control" type="text" placeholder="填写接收人手机号" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "msgTemplate/msgTemplate"
    $("#form-msgTemplate-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var ary = $("#params").val().split(',')
            var paramNum = $("input[name='paramNum']").val()
            if (ary.length != paramNum) {
                $.modal.msgError("请求参数个数有误")
                return false;
            }

            var phoneNum = $("#phoneNum").val();

            if (!(/^1[34578]\d{9}$/.test(phoneNum))) {
                $.modal.msgError("手机号格式有误")
                return false;
            }
            $.operate.save(prefix + "/sendMsg", $('#form-msgTemplate-add').serialize());
        }
    }
</script>
</body>
</html>